package gui

import swing._
import java.awt.Color
import java.awt.Cursor
import java.awt.Font
import scala.swing.ScrollPane
import javax.swing.text.EditorKit
import scala.swing.EditorPane

/**
 * Diese Klasse erbt von ScrollPane und erweitert diese
 * um eine TextArea. Zusaetzlich werden Linehighlighter
 * sowie Syntaxhighlighter festgelegt.
 */

class ScrollTextAreaPane(edit:Boolean) extends ScrollPane {
  
  var editorKit:EditorKit = null
  var textarea = new EditorPane {
    font = new Font("Courier New", 0, 12)
    if(!edit)
      editable = false
  }
  setEditorKit(HighlighterSyntax.getEditorKit, "text/ada")
  
  var borderlayout = new BorderPanel() {
    add(textarea, BorderPanel.Position.Center)
  }
  contents = borderlayout
  if(edit == true)
    this.cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR) 
  peer.getVerticalScrollBar().setUnitIncrement(16)
  peer.setVerticalScrollBarPolicy(22)
  
  var linelighter:LineHighlighter = null
  if(edit == true) {
    var leichtesOrange = new Color(255,236,198)
    var leichtesBlau = new Color(231,230,255)
    linelighter = new LineHighlighter(textarea.peer, leichtesBlau)
    linelighter.setSelectionColor(textarea.peer.getSelectionColor)
  }

  def getText() : String = textarea.text
  
  def setText(t:String) = {
    textarea.text = t
  }
  
  def setEditorKit(editkit: EditorKit, ctype: String) = {
    editorKit = editkit
    textarea.peer.setEditorKitForContentType(ctype, editorKit);
    textarea.peer.setContentType(ctype);
  }
  
}


 